import {uniqueId} from "lodash";
import { getClassificationListDataToCode} from "@/pages/Dashboard/Knowledge/service";
import {ProFormTreeSelect} from "@ant-design/pro-form";

const KnowledgSystemSelect = (
    {
        code,
        type,
        onChange,
    }:{
        code:string;
        type:string;
        onChange?:(val:string)=>void;
    }
) => {
    //获取目录树结构，使其与组件可识别的结构一致
    const getSedTree = (data?: AircasKB.Knowledge.classificationListResponse[]) => {
        let office = data?.map(item => {
            // @ts-ignore
            const result:any = {
                title:item.name,
                value:item.code,
                key:item.code,
                children:getSedTree(item.childList)
            }
            return result
        })
        return office
    }
    return (
        <ProFormTreeSelect
            key={uniqueId()}
            placeholder="请选择"
            fieldProps={{
                showSearch: false,
                showArrow: true,
                treeDefaultExpandAll:true,
                style: {
                    width: '300px',
                },
                // showCheckedStrategy:"SHOW_PARENT"
            }
            }
            request={async () => {
                const res = await getClassificationListDataToCode({
                    code:code,
                    type:type
                });
                return getSedTree(res.data) || [];
            }}
        />
    )
}

export default KnowledgSystemSelect;
